/**
 * @ClassName: DicVipgradeUtils
 * @author 830
 * @date 2016骞?10鏈?26鏃?
 */
package com.fzrskj.cloud.free.dic.utils;

import com.fzrskj.cloud.free.dic.dao.DicVipgradeDao;
import com.fzrskj.cloud.free.dic.bean.DicVipgrade;
import ms.core.consts.SysErr;
import ms.core.object.CObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DicVipgradeUtils extends CObject{
	/**
	 * 根据code查询会员等级
	 * @return
	 */
	public DicVipgrade queryDicVipgradeByCode(String levelCode){
		DicVipgradeDao dao=new DicVipgradeDao();
		DicVipgrade queryDicVipgradeByCode = dao.queryDicVipgradeByCode(levelCode);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return queryDicVipgradeByCode;
	}

	/**
	 * 根据Name查询会员等级
	 * @param levelName name.
	 * @return
	 */
	public DicVipgrade queryDicVipgradeByName(String levelName){
		DicVipgradeDao dao=new DicVipgradeDao();
		DicVipgrade queryDicVipgradeByCode = dao.queryDicVipgradeByName(levelName);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return queryDicVipgradeByCode;
	}

	/**
	 * 分页查询会员等级列表
	 * @return
	 */
	public List<DicVipgrade> queryDicVipgradeList(Map<String, Object> cdt, int page,int pageSize) {
		DicVipgradeDao dao=new DicVipgradeDao();
		List<DicVipgrade> list = dao.queryDicVipgradeList(cdt, page, pageSize);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return list;
	}

	public List<DicVipgrade> queryDicVipgradeListFree(Map<String, Object> cdt, int page,int pageSize) {
		DicVipgradeDao dao=new DicVipgradeDao();
		List<DicVipgrade> list = dao.queryDicVipgradeListFree(cdt, page, pageSize);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return list;
	}

	/**
	 * 查询会员等级列表
	 * @return
	 */
	public List<DicVipgrade> querySysVipgrade(){
		DicVipgradeDao dao=new DicVipgradeDao();
		List<DicVipgrade> list = dao.querySysVipgrade();
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return list;
	}

	//to query Vipgrade for rows
	public int queryVipgrade(Map<String, Object> cdt){
		DicVipgradeDao dao = new DicVipgradeDao();
		int rows = dao.queryDicVipgrade(cdt);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		if(!code.equals(SysErr.CODE_SUCCESS)){
			return -1;
		}
		return rows;
	}

	// 添加会员级别
	public int addVipgrade(Map<String, Object> gr){
		DicVipgradeDao dao = new DicVipgradeDao();
		DicVipgrade vg = new DicVipgrade();
		vg.setLevelCode((String)gr.get("levelCode"));
		vg.setLevelName((String)gr.get("levelName"));
		vg.setMaxCharge((Double)gr.get("maxCharge"));
		vg.setMinCharge((Double)gr.get("minCharge"));
		vg.setRankIco((String)gr.get("rankIco"));
		vg.setRebate((Double)gr.get("rebate"));
		vg.setShowIndex((Integer)gr.get("showIndex"));
		int ret = dao.addDicVipgrade(vg);
		String code = dao.getErrCode();
		this.setErrCode(code);
		vg = null;
		dao.dispose();
		return ret;
	}

	public int addVipgradeFree(Map<String, Object> values){
		DicVipgradeDao dao = new DicVipgradeDao();
		int ret = dao.addDicVipgradeFree(values);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ret;
	}

	//修改会员等级
	public int uptVipgrade(Map<String, Object> gr){
		DicVipgradeDao dao = new DicVipgradeDao();
		Map<String, Object> cdt = new HashMap<String, Object>();
		Map<String, Object> value = new HashMap<String, Object>();
		value.put("id", (Integer)gr.get("id"));
		cdt.put("levelCode", (String)gr.get("levelCode"));
		cdt.put("levelName", (String)gr.get("levelName"));
		cdt.put("maxCharge", (Double)gr.get("maxCharge"));
		cdt.put("minCharge", (Double)gr.get("minCharge"));
		cdt.put("rankIco", (String)gr.get("rankIco"));
		cdt.put("rebate", (Double)gr.get("rebate"));
		cdt.put("showIndex", (Integer)gr.get("showIndex"));
		int ret = dao.updateDicVipgrade(cdt, value);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ret;
	}

	//删除会员等级
	public int delDicVipgrade(Integer id){
		DicVipgradeDao dao = new DicVipgradeDao();
		Map<String, Object> cdt = new HashMap<String, Object>();
		cdt.put("id", id);
		int ret = dao.delDicVipgrade(cdt);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return ret;
	}

	//根据会员Id查询会员等级
	public DicVipgrade queryDicVipgradeByUid(int userId){
		DicVipgradeDao dao = new DicVipgradeDao();
		DicVipgrade view = dao.queryDicVipgradeByUid(userId);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return view;
	}

	public DicVipgrade queryDicVipgradeByUidAppointAgent(Integer userId, Integer agentId) {
		DicVipgradeDao dao = new DicVipgradeDao();
		DicVipgrade view = dao.queryDicVipgradeByUidAppointAgent(userId, agentId);
		String code = dao.getErrCode();
		this.setErrCode(code);
		dao.dispose();
		return view;
	}

}